using System;
using System.Data;

namespace RingBufferStream.Utils.Database
{
  /// <summary>
  /// Contract for implementing a custom stored procedure.
  /// It is recommended to rather derive from <see cref="BaseStoredProcedure"/>.
  /// </summary>
  public interface IStoredProcedure
  {
    /// <summary>
    /// Command text specifying the stored procedure name to use during invocation.
    /// </summary>
    string CommandText { get; }

    /// <summary>
    /// Property for explicitly stating whether a result set is expected.
    /// </summary>
    bool HasResultSet { get; }

    /// <summary>
    /// Method for adding and setting parameter values.
    /// </summary>
    /// <param name="command">The command object to add\set parameters on.</param>
    void SetParameters(IDbCommand command);

    /// <summary>
    /// Method for preparing any state on the reader before the execution.
    /// </summary>
    /// <param name="reader">Reader object that will be used before and after stored procedure execution.</param>
    void StartRead(IDataReader reader);

    /// <summary>
    /// Method for reading the current field values from the data record.
    /// </summary>
    /// <param name="record">Reader object with the data record fields.</param>
    void ReadRecord(IDataRecord record);

    /// <summary>
    /// Method for reading the output parameter values added with the <see cref="SetParameters"/> method.
    /// </summary>
    /// <param name="command">Command object that was used for executing the stored procedure.</param>
    void FinishRead(IDbCommand command);

    /// <summary>
    /// Method for escalating the exception that occurred during execution of the stored procedure.
    /// </summary>
    /// <param name="exception">The exception being escalated.</param>
    void FinishRead(Exception exception);
  }
}
